<template>
	<view>
		<view class="w100">
			<view class="u-m-20 u-p-20 bg-white radius">
				<u-form-item class="u-p-40" label-width="100" label="旧密码" prop="name">
					<u-input v-model="form.oldpwd" @input="xwatch" placeholder-style='fontSize:36upx' placeholder="请输入旧密码" />
				</u-form-item>
				<u-form-item class="u-p-40 " label-width="100" label="新密码" prop="name">
					<u-input type="password" v-model="form.pwd" @input="xwatch" placeholder-style='fontSize:36upx' placeholder="请输入新密码"/>
				</u-form-item>
				<view class="u-flex u-m-t-30">
					<u-button :type="disabledbtn?'default':'primary'" :disabled="disabledbtn" @click="subbtn()" style="width: 100%;">立即提交</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.$u.http.config.baseUrl,
				form:{
					oldpwd:'',
					pwd:''
				},
				disabledbtn:true,//按钮状态
			}
		},
		onLoad: function(e) {
			const value = uni.getStorageSync('userinfo');
			this.form.user_id = value['_id'];
		},
		methods: {
			subbtn(){
				var res = this.verify();
				if(res==1){
					this.$u.api.setPassword(this.form).then(res=>{
						uni.showToast({
							title:'修改成功',
							icon:'success'
						})
						setTimeout(res=>{
							uni.navigateBack({
								
							})
						},1000)
					}).catch(res=>{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					})
				}
			},
			xwatch(){
				if(this.form.oldpwd!=''&&this.form.pwd!=''){
					this.disabledbtn = false;
				}else{
					this.disabledbtn = true;
				}
			},
			verify(){	
				//验证
				if(this.form.pwd.length<6){
					uni.showToast({
						title:'密码不能小于6位',
						icon:'none',
						duration:1000
					})
					return 0;
				}
				if(this.form.oldpwd == this.form.pwd){
					uni.showToast({
						title:'不能与旧密码一样',
						icon:'none',
						duration:1000
					})
					return 0;
				}
				// if(this.form.pwd != this.form.pwd2){
				// 	uni.showToast({
				// 		title:'两次密码不一样',
				// 		icon:'none',
				// 		duration:1000
				// 	})
				// 	return 0;
				// }
				return 1
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
